/**
 * 二审提交
 */
import * as React from 'react'
import { Form, message } from 'antd'
import Authentication from '../../router/Authentication'
import { FormComponentProps } from 'antd/lib/form/Form'
import { PageHeaderLayout, BaseInfo, ConstDes, CateInfo, CateImg } from '../../components'
import '../../assets/style/detail.less'
import { post, EDIT_SECONINS_INFO, DATA_CHECK } from '../../service/api'
export interface Props{
  sample: any
  sampleImgs: any
  workStatus: any []
  checkList: any []
  roleScore: any []
  sampleScore: any []
  history: any
  pullData: any
}

export interface State {
  shVisible: boolean
  hxVisible: boolean
  ysVisible: boolean
  tab: string
}
const tabList = [
  {
    key: 'baseInfo',
    tab: '基础资料',
  },
  {
    key: 'cateInfo',
    tab: '品类数据分析'
  },
  {
    key: 'pics',
    tab: '图片库'
  },
  {
    key: 'costDes',
    tab: '成本分解',
  },
]
@Authentication
class SecordSubmitDetail extends React.Component<Props & FormComponentProps, State> {
  state = {
    shVisible: false,
    hxVisible: false,
    ysVisible: false,
    tab: tabList[0].key,
  }
  onTabChange = (tab: string) => {
    this.setState({
      ...this.state,
      tab
    })
  }
  handleSave = (e: any) => {
    e.preventDefault()
    const { form } = this.props
    form.validateFields((err: any, fieldsValue: any) => {
      if (err) return
      const { sample } = this.props
      let data = {
        ...sample,
        ...fieldsValue
      }
      post(EDIT_SECONINS_INFO, data).then((res: any) => {
        if (res.code == '1') {
          message.success('操作成功！')
        }else {
          message.error(res.errMsg)
        }
      })
    })
  }
  handleSecordSubmit = () => {
    const { sample } = this.props
    post(DATA_CHECK, { ids: sample.sampleId }).then((res: any) => {
      if (res.code == '1') {
        message.success('操作成功！')
      }else {
        message.error(res.errMsg)
      }
    })
  }
  render () {
    const { tab } = this.state
    const { sampleImgs, history } = this.props
    function getPage(): any {
      if(tab == 'baseInfo') 
        return (<BaseInfo
          onSubmit = {() => history.push({ pathname: '/twosub' })}
          type={1}
          sampleImgs = {sampleImgs}
        />)
      else if(tab == 'costDes')
        return (<ConstDes />)
      else if(tab == 'cateInfo')
        return (<CateInfo />)
      else if(tab == 'pics')
        return (<CateImg />)
      else return ''
    }
    return (
      <PageHeaderLayout 
        title = ""
        tabList={tabList}
        onTabChange = {this.onTabChange}
        tabDefaultActiveKey = "baseInfo">
        {getPage()}
      </PageHeaderLayout>
    )
  }
}
export default Form.create()(SecordSubmitDetail)
